package com.monochromebytes.mononet.test;
import java.io.Serializable;

import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Shape;
import org.newdawn.slick.geom.Vector2f;

public abstract class Collidable implements Updatable, Renderable, Serializable {

    private static final long serialVersionUID = 2405094322788318983L;

    private Shape shape;
    private Shape lastShape;

    public void init(Shape shape) {
        this.shape = shape;
        this.lastShape = shape;
    }

    @Override
    public void render(Graphics g) {
        if (this.shape != null) {
            g.setAntiAlias(true);
            g.draw(this.shape);
        }
    }

    @Override
    public void update(int delta) {
        this.lastShape = this.shape;
        this.shape = this.calculateShape(this.shape, delta);
    }

    public abstract Shape calculateShape(Shape shape, float delta);

    public void moveToLastShape() {
        this.shape = this.lastShape;
    }

    public Vector2f getPosition() {
        return new Vector2f(this.shape.getCenter());
    }

    public boolean collidesWith(Collidable other) {
        return Collider.isColliding(this, other);
    }

    public Shape getShape() {
        return this.shape;
    }

    public Shape getLastShape() {
        return this.lastShape;
    }

    public void setPosition(int x, int y) {
        this.shape.setCenterX(x);
        this.shape.setCenterY(y);
    }
}
